package com.song.boot.springstudy.netty.commhandler;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

// 出站处理器：将字符串转为字节
// 译码器
public class StringEncoderCustomization extends ChannelOutboundHandlerAdapter {
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        String message = (String) msg;
        ByteBuf buffer = Unpooled.copiedBuffer(message, io.netty.util.CharsetUtil.UTF_8);
        ctx.write(buffer, promise); // 传递给下一个处理器
    }
}